{ ***  cef_v8_capi.h  *** }

  PCefV8Handler = ^TCefV8Handler;
  PCefV8Accessor = ^TCefV8Accessor;
  PCefV8Exception = ^TCefV8Exception;
  PCefV8Value = ^TCefV8Value;
  PCefV8ValueArray = array[0..(High(Integer) div SizeOf(Integer)) - 1] of PCefV8Value;
  PCefV8StackTrace = ^TCefV8StackTrace;
  PCefV8StackFrame = ^TCefV8StackFrame;
  PPCefV8Value = ^PCefV8ValueArray;


  // Structure representing a V8 context handle. V8 handles can only be accessed
  // from the thread on which they are created. Valid threads for creating a V8
  // handle include the render process main thread (TID_RENDERER) and WebWorker
  // threads. A task runner for posting tasks on the associated thread can be
  // retrieved via the cef_v8context_t::get_task_runner() function.
  TCefV8Context = record
    // Base structure.
    base: TCefBase;

    // Returns the task runner associated with this context. V8 handles can only
    // be accessed from the thread on which they are created. This function can be
    // called on any render process thread.
    get_task_runner: function(self: PCefv8Context): PCefTask; cconv;

    // Returns true (1) if the underlying handle is valid and it can be accessed
    // on the current thread. Do not call any other functions if this function
    // returns false (0).
    is_valid: function(self: PCefv8Context): Integer; cconv;

    // Returns the browser for this context. This function will return an NULL
    // reference for WebWorker contexts.
    get_browser: function(self: PCefv8Context): PCefBrowser; cconv;

    // Returns the frame for this context. This function will return an NULL
    // reference for WebWorker contexts.
    get_frame: function(self: PCefv8Context): PCefFrame; cconv;

    // Returns the global object for this context. The context must be entered
    // before calling this function.
    get_global: function(self: PCefv8Context): PCefv8Value; cconv;

    // Enter this context. A context must be explicitly entered before creating a
    // V8 Object, Array, Function or Date asynchronously. exit() must be called
    // the same number of times as enter() before releasing this context. V8
    // objects belong to the context in which they are created. Returns true (1)
    // if the scope was entered successfully.
    enter: function(self: PCefv8Context): Integer; cconv;

    // Exit this context. Call this function only after calling enter(). Returns
    // true (1) if the scope was exited successfully.
    exit: function(self: PCefv8Context): Integer; cconv;

    // Returns true (1) if this object is pointing to the same handle as |that|
    // object.
    is_same: function(self, that: PCefv8Context): Integer; cconv;

    // Evaluates the specified JavaScript code using this context's global object.
    // On success |retval| will be set to the return value, if any, and the
    // function will return true (1). On failure |exception| will be set to the
    // exception, if any, and the function will return false (0).
    eval: function(self: PCefv8Context; const code: PCefString;
      var retval: PCefv8Value; var exception: PCefV8Exception): Integer; cconv;
  end;


  // Structure that should be implemented to handle V8 function calls. The
  // functions of this structure will be called on the thread associated with the
  // V8 function.
  TCefV8Handler = record
    // Base structure.
    base: TCefBase;

    // Handle execution of the function identified by |name|. |object| is the
    // receiver ('this' object) of the function. |arguments| is the list of
    // arguments passed to the function. If execution succeeds set |retval| to the
    // function return value. If execution fails set |exception| to the exception
    // that will be thrown. Return true (1) if execution was handled.
    {$NOTE check var usage}
    execute: function(self: PCefv8Handler; const name: PCefString; object_: PCefv8Value;
      argumentsCount: csize_t; arguments: PPCefV8Value; out retval: PCefV8Value;
      var exception: TCefString): Integer; cconv;
        //exception: PCefString): Integer; cconv;
  end;


  // Structure that should be implemented to handle V8 accessor calls. Accessor
  // identifiers are registered by calling cef_v8value_t::set_value_byaccessor().
  // The functions of this structure will be called on the thread associated with
  // the V8 accessor.
  TCefV8Accessor = record
    // Base structure.
    base: TCefBase;

    // Handle retrieval the accessor value identified by |name|. |object| is the
    // receiver ('this' object) of the accessor. If retrieval succeeds set
    // |retval| to the return value. If retrieval fails set |exception| to the
    // exception that will be thrown. Return true (1) if accessor retrieval was
    // handled.
    get: function(self: PCefV8Accessor; const name: PCefString;
      object_: PCefv8Value; out retval: PCefv8Value; exception: PCefString): Integer; cconv;

    // Handle assignment of the accessor value identified by |name|. |object| is
    // the receiver ('this' object) of the accessor. |value| is the new value
    // being assigned to the accessor. If assignment fails set |exception| to the
    // exception that will be thrown. Return true (1) if accessor assignment was
    // handled.
    set_: function(self: PCefV8Accessor; const name: PCefString;
      obj: PCefv8Value; value: PCefv8Value; exception: PCefString): Integer; cconv;
  end;


  // Structure representing a V8 exception. The functions of this structure may be
  // called on any render process thread.
  TCefV8Exception = record
    // Base structure.
    base: TCefBase;

    // Returns the exception message.
    //
    // The resulting string must be freed by calling cef_string_userfree_free().
    get_message: function(self: PCefV8Exception): PCefStringUserFree; cconv;

    // Returns the line of source code that the exception occurred within.
    //
    // The resulting string must be freed by calling cef_string_userfree_free().
    get_source_line: function(self: PCefV8Exception): PCefStringUserFree; cconv;

    // Returns the resource name for the script from where the function causing
    // the error originates.
    //
    // The resulting string must be freed by calling cef_string_userfree_free().
    get_script_resource_name: function(self: PCefV8Exception): PCefStringUserFree; cconv;

    // Returns the 1-based number of the line where the error occurred or 0 if the
    // line number is unknown.
    get_line_number: function(self: PCefV8Exception): Integer; cconv;

    // Returns the index within the script of the first character where the error
    // occurred.
    get_start_position: function(self: PCefV8Exception): Integer; cconv;

    // Returns the index within the script of the last character where the error
    // occurred.
    get_end_position: function(self: PCefV8Exception): Integer; cconv;

    // Returns the index within the line of the first character where the error
    // occurred.
    get_start_column: function(self: PCefV8Exception): Integer; cconv;

    // Returns the index within the line of the last character where the error
    // occurred.
    get_end_column: function(self: PCefV8Exception): Integer; cconv;
  end;


  // Structure representing a V8 value handle. V8 handles can only be accessed
  // from the thread on which they are created. Valid threads for creating a V8
  // handle include the render process main thread (TID_RENDERER) and WebWorker
  // threads. A task runner for posting tasks on the associated thread can be
  // retrieved via the cef_v8context_t::get_task_runner() function.
  TCefV8Value = record
    // Base structure.
    base: TCefBase;

    // Returns true (1) if the underlying handle is valid and it can be accessed
    // on the current thread. Do not call any other functions if this function
    // returns false (0).
    is_valid: function(self: PCefv8Value): Integer; cconv;

    // True if the value type is undefined.
    is_undefined: function(self: PCefv8Value): Integer; cconv;

    // True if the value type is null.
    is_null: function(self: PCefv8Value): Integer; cconv;

    // True if the value type is bool.
    is_bool: function(self: PCefv8Value): Integer; cconv;

    // True if the value type is int.
    is_int: function(self: PCefv8Value): Integer; cconv;

    // True if the value type is unsigned int.
    is_uint: function(self: PCefv8Value): Integer; cconv;

    // True if the value type is double.
    is_double: function(self: PCefv8Value): Integer; cconv;

    // True if the value type is Date.
    is_date: function(self: PCefv8Value): Integer; cconv;

    // True if the value type is string.
    is_string: function(self: PCefv8Value): Integer; cconv;

    // True if the value type is object.
    is_object: function(self: PCefv8Value): Integer; cconv;

    // True if the value type is array.
    is_array: function(self: PCefv8Value): Integer; cconv;

    // True if the value type is function.
    is_function: function(self: PCefv8Value): Integer; cconv;

    // Returns true (1) if this object is pointing to the same handle as |that|
    // object.
    is_same: function(self, that: PCefv8Value): Integer; cconv;

    // Return a bool value.  The underlying data will be converted to if
    // necessary.
    get_bool_value: function(self: PCefv8Value): Integer; cconv;

    // Return an int value.  The underlying data will be converted to if
    // necessary.
    get_int_value: function(self: PCefv8Value): Integer; cconv;

    // Return an unisgned int value.  The underlying data will be converted to if
    // necessary.
    get_uint_value: function(self: PCefv8Value): UInt32; cconv;

    // Return a double value.  The underlying data will be converted to if
    // necessary.
    get_double_value: function(self: PCefv8Value): Double; cconv;

    // Return a Date value.  The underlying data will be converted to if
    // necessary.
    get_date_value: function(self: PCefv8Value): TCefTime; cconv;

    // Return a string value.  The underlying data will be converted to if
    // necessary.
    //
    // The resulting string must be freed by calling cef_string_userfree_free().
    get_string_value: function(self: PCefv8Value): PCefStringUserFree; cconv;


    // OBJECT METHODS - These functions are only available on objects. Arrays and
    // functions are also objects. String- and integer-based keys can be used
    // interchangably with the framework converting between them as necessary.

    // Returns true (1) if this is a user created object.
    is_user_created: function(self: PCefv8Value): Integer; cconv;

    // Returns true (1) if the last function call resulted in an exception. This
    // attribute exists only in the scope of the current CEF value object.
    has_exception: function(self: PCefv8Value): Integer; cconv;

    // Returns the exception resulting from the last function call. This attribute
    // exists only in the scope of the current CEF value object.
    get_exception: function(self: PCefv8Value): PCefV8Exception; cconv;

    // Clears the last exception and returns true (1) on success.
    clear_exception: function(self: PCefv8Value): Integer; cconv;

    // Returns true (1) if this object will re-throw future exceptions. This
    // attribute exists only in the scope of the current CEF value object.
    will_rethrow_exceptions: function(self: PCefv8Value): Integer; cconv;

    // Set whether this object will re-throw future exceptions. By default
    // exceptions are not re-thrown. If a exception is re-thrown the current
    // context should not be accessed again until after the exception has been
    // caught and not re-thrown. Returns true (1) on success. This attribute
    // exists only in the scope of the current CEF value object.
    set_rethrow_exceptions: function(self: PCefv8Value; rethrow: Integer): Integer; cconv;

    // Returns true (1) if the object has a value with the specified identifier.
    has_value_bykey: function(self: PCefv8Value; const key: PCefString): Integer; cconv;

    // Returns true (1) if the object has a value with the specified identifier.
    has_value_byindex: function(self: PCefv8Value; index: Integer): Integer; cconv;

    // Deletes the value with the specified identifier and returns true (1) on
    // success. Returns false (0) if this function is called incorrectly or an
    // exception is thrown. For read-only and don't-delete values this function
    // will return true (1) even though deletion failed.
    delete_value_bykey: function(self: PCefv8Value; const key: PCefString): Integer; cconv;

    // Deletes the value with the specified identifier and returns true (1) on
    // success. Returns false (0) if this function is called incorrectly, deletion
    // fails or an exception is thrown. For read-only and don't-delete values this
    // function will return true (1) even though deletion failed.
    delete_value_byindex: function(self: PCefv8Value; index: Integer): Integer; cconv;

    // Returns the value with the specified identifier on success. Returns NULL if
    // this function is called incorrectly or an exception is thrown.
    get_value_bykey: function(self: PCefv8Value; const key: PCefString): PCefv8Value; cconv;

    // Returns the value with the specified identifier on success. Returns NULL if
    // this function is called incorrectly or an exception is thrown.
    get_value_byindex: function(self: PCefv8Value; index: Integer): PCefv8Value; cconv;

    // Associates a value with the specified identifier and returns true (1) on
    // success. Returns false (0) if this function is called incorrectly or an
    // exception is thrown. For read-only values this function will return true
    // (1) even though assignment failed.
    set_value_bykey: function(self: PCefv8Value; const key: PCefString;
      value: PCefv8Value; attribute: TCefV8PropertyAttribute): Integer; cconv;

    // Associates a value with the specified identifier and returns true (1) on
    // success. Returns false (0) if this function is called incorrectly or an
    // exception is thrown. For read-only values this function will return true
    // (1) even though assignment failed.
    set_value_byindex: function(self: PCefv8Value; index: Integer;
       value: PCefv8Value): Integer; cconv;

    // Registers an identifier and returns true (1) on success. Access to the
    // identifier will be forwarded to the cef_v8accessor_t instance passed to
    // cef_v8value_t::cef_v8value_create_object(). Returns false (0) if this
    // function is called incorrectly or an exception is thrown. For read-only
    // values this function will return true (1) even though assignment failed.
    {$NOTE Integer -> TCefV8AccessControl / TCefV8PropertyAttribute}
    set_value_byaccessor: function(self: PCefv8Value; const key: PCefString;
      settings: TCefV8AccessControl; attribute: TCefV8PropertyAttribute): Integer; cconv;

    // Read the keys for the object's values into the specified vector. Integer-
    // based keys will also be returned as strings.
    get_keys: function(self: PCefv8Value; keys: TCefStringList): Integer; cconv;

    // Sets the user data for this object and returns true (1) on success. Returns
    // false (0) if this function is called incorrectly. This function can only be
    // called on user created objects.
    set_user_data: function(self: PCefv8Value; user_data: PCefBase): Integer; cconv;

    // Returns the user data, if any, assigned to this object.
    get_user_data: function(self: PCefv8Value): PCefBase; cconv;

    // Returns the amount of externally allocated memory registered for the
    // object.
    get_externally_allocated_memory: function(self: PCefv8Value): Integer; cconv;

    // Adjusts the amount of registered external memory for the object. Used to
    // give V8 an indication of the amount of externally allocated memory that is
    // kept alive by JavaScript objects. V8 uses this information to decide when
    // to perform global garbage collection. Each cef_v8value_t tracks the amount
    // of external memory associated with it and automatically decreases the
    // global total by the appropriate amount on its destruction.
    // |change_in_bytes| specifies the number of bytes to adjust by. This function
    // returns the number of bytes associated with the object after the
    // adjustment. This function can only be called on user created objects.
    adjust_externally_allocated_memory: function(self: PCefv8Value; change_in_bytes: Integer): Integer; cconv;


    // ARRAY METHODS - These functions are only available on arrays.

    // Returns the number of elements in the array.
    get_array_length: function(self: PCefv8Value): Integer; cconv;


    // FUNCTION METHODS - These functions are only available on functions.

    // Returns the function name.
    //
    // The resulting string must be freed by calling cef_string_userfree_free().
    get_function_name: function(self: PCefv8Value): PCefStringUserFree; cconv;

    // Returns the function handler or NULL if not a CEF-created function.
    get_function_handler: function(self: PCefv8Value): PCefv8Handler; cconv;

    // Execute the function using the current V8 context. This function should
    // only be called from within the scope of a cef_v8handler_t or
    // cef_v8accessor_t callback, or in combination with calling enter() and
    // exit() on a stored cef_v8context_t reference. |object| is the receiver
    // ('this' object) of the function. If |object| is NULL the current context's
    // global object will be used. |arguments| is the list of arguments that will
    // be passed to the function. Returns the function return value on success.
    // Returns NULL if this function is called incorrectly or an exception is
    // thrown.
    execute_function: function(self: PCefv8Value; object_: PCefv8Value;
      argumentsCount: csize_t; const arguments: PPCefV8Value): PCefv8Value; cconv;

    // Execute the function using the specified V8 context. |object| is the
    // receiver ('this' object) of the function. If |object| is NULL the specified
    // context's global object will be used. |arguments| is the list of arguments
    // that will be passed to the function. Returns the function return value on
    // success. Returns NULL if this function is called incorrectly or an
    // exception is thrown.
    execute_function_with_context: function(self: PCefv8Value; context: PCefv8Context;
      object_: PCefv8Value; argumentsCount: csize_t; const arguments: PPCefV8Value): PCefv8Value; cconv;
  end;


  // Structure representing a V8 stack trace handle. V8 handles can only be
  // accessed from the thread on which they are created. Valid threads for
  // creating a V8 handle include the render process main thread (TID_RENDERER)
  // and WebWorker threads. A task runner for posting tasks on the associated
  // thread can be retrieved via the cef_v8context_t::get_task_runner() function.
  TCefV8StackTrace = record
    // Base structure.
    base: TCefBase;

    // Returns true (1) if the underlying handle is valid and it can be accessed
    // on the current thread. Do not call any other functions if this function
    // returns false (0).
    is_valid: function(self: PCefV8StackTrace): Integer; cconv;

    // Returns the number of stack frames.
    get_frame_count: function(self: PCefV8StackTrace): Integer; cconv;

    // Returns the stack frame at the specified 0-based index.
    get_frame: function(self: PCefV8StackTrace; index: Integer): PCefV8StackFrame; cconv;
  end;


  // Structure representing a V8 stack frame handle. V8 handles can only be
  // accessed from the thread on which they are created. Valid threads for
  // creating a V8 handle include the render process main thread (TID_RENDERER)
  // and WebWorker threads. A task runner for posting tasks on the associated
  // thread can be retrieved via the cef_v8context_t::get_task_runner() function.
  TCefV8StackFrame = record
    // Base structure.
    base: TCefBase;

    // Returns true (1) if the underlying handle is valid and it can be accessed
    // on the current thread. Do not call any other functions if this function
    // returns false (0).
    is_valid: function(self: PCefV8StackFrame): Integer; cconv;

    // Returns the name of the resource script that contains the function.
    //
    // The resulting string must be freed by calling cef_string_userfree_free().
    get_script_name: function(self: PCefV8StackFrame): PCefStringUserFree; cconv;

    // Returns the name of the resource script that contains the function or the
    // sourceURL value if the script name is undefined and its source ends with a
    // "//@ sourceURL=..." string.
    //
    // The resulting string must be freed by calling cef_string_userfree_free().
    get_script_name_or_source_url: function(self: PCefV8StackFrame): PCefStringUserFree; cconv;

    // Returns the name of the function.
    //
    // The resulting string must be freed by calling cef_string_userfree_free().
    get_function_name: function(self: PCefV8StackFrame): PCefStringUserFree; cconv;

    // Returns the 1-based line number for the function call or 0 if unknown.
    get_line_number: function(self: PCefV8StackFrame): Integer; cconv;

    // Returns the 1-based column offset on the line for the function call or 0 if
    // unknown.
    get_column: function(self: PCefV8StackFrame): Integer; cconv;

    // Returns true (1) if the function was compiled using eval().
    is_eval: function(self: PCefV8StackFrame): Integer; cconv;

    // Returns true (1) if the function was called as a constructor via "new".
    is_constructor: function(self: PCefV8StackFrame): Integer; cconv;
  end;

    // Returns the current (top) context object in the V8 context stack.
    tfn_cef_v8context_get_current_context = function: PCefv8Context; cdecl;

    // Returns the entered (bottom) context object in the V8 context stack.
    tfn_cef_v8context_get_entered_context = function: PCefv8Context; cdecl;

    // Returns true (1) if V8 is currently inside a context.
    tfn_cef_v8context_in_context = function: Integer;



    // Create a new TCefv8Value object of type undefined.
    tfn_cef_v8value_create_undefined = function: PCefv8Value; cdecl;

    // Create a new TCefv8Value object of type null.
    tfn_cef_v8value_create_null = function: PCefv8Value; cdecl;

    // Create a new TCefv8Value object of type bool.
    tfn_cef_v8value_create_bool = function(
        value: Integer): PCefv8Value; cdecl;

    // Create a new TCefv8Value object of type int.
    tfn_cef_v8value_create_int = function(
        value: Int32): PCefv8Value; cdecl;

    // Create a new TCefv8Value object of type unsigned int.
    tfn_cef_v8value_create_uint = function(
        value: UInt32): PCefv8Value; cdecl;

    // Create a new TCefv8Value object of type double.
    tfn_cef_v8value_create_double = function(
        value: Double): PCefv8Value; cdecl;

    // Create a new TCefv8Value object of type Date. This function should only be
    // called from within the scope of a cef_v8context_tHandler, cef_v8handler_t or
    // cef_v8accessor_t callback, or in combination with calling enter() and exit()
    // on a stored cef_v8context_t reference.
    tfn_cef_v8value_create_date = function(
        const value: PCefTime): PCefv8Value; cdecl;

    // Create a new TCefv8Value object of type string.
    tfn_cef_v8value_create_string = function(
        const value: PCefString): PCefv8Value; cdecl;

    // Create a new TCefv8Value object of type object with optional accessor. This
    // function should only be called from within the scope of a
    // cef_v8context_tHandler, cef_v8handler_t or cef_v8accessor_t callback, or in
    // combination with calling enter() and exit() on a stored cef_v8context_t
    // reference.
    tfn_cef_v8value_create_object = function(
        accessor: PCefV8Accessor): PCefv8Value; cdecl;

    // Create a new TCefv8Value object of type array with the specified |length|.
    // If |length| is negative the returned array will have length 0. This function
    // should only be called from within the scope of a cef_v8context_tHandler,
    // cef_v8handler_t or cef_v8accessor_t callback, or in combination with calling
    // enter() and exit() on a stored cef_v8context_t reference.
    tfn_cef_v8value_create_array = function(
        length: Integer): PCefv8Value; cdecl;

    // Create a new TCefv8Value object of type function. This function should only
    // be called from within the scope of a cef_v8context_tHandler, cef_v8handler_t
    // or cef_v8accessor_t callback, or in combination with calling enter() and
    // exit() on a stored cef_v8context_t reference.
    tfn_cef_v8value_create_function = function(
        const name: PCefString;
        handler: PCefv8Handler): PCefv8Value; cdecl;



    // Returns the stack trace for the currently active context. |frame_limit| is
    // the maximum number of frames that will be captured.
    tfn_cef_v8stack_trace_get_current = function(
        frame_limit: Integer): PCefV8StackTrace; cdecl;



    // Register a new V8 extension with the specified JavaScript extension code and
    // handler. Functions implemented by the handler are prototyped using the
    // keyword 'native'. The calling of a native function is restricted to the scope
    // in which the prototype of the native function is defined. This function may
    // only be called on the render process main thread.
    //
    // Example JavaScript extension code: <pre>
    //   // create the 'example' global object if it doesn't already exist.
    //   if (!example)
    //     example = {};
    //   // create the 'example.test' global object if it doesn't already exist.
    //   if (!example.test)
    //     example.test = {};
    //   (function() {
    //     // Define the function 'example.test.myfunction'.
    //     example.test.myfunction = function() {
    //       // Call CefV8Handler::Execute() with the function name 'MyFunction'
    //       // and no arguments.
    //       native function MyFunction();
    //       return MyFunction();
    //     };
    //     // Define the getter function for parameter 'example.test.myparam'.
    //     example.test.__defineGetter__('myparam', function() {
    //       // Call CefV8Handler::Execute() with the function name 'GetMyParam'
    //       // and no arguments.
    //       native function GetMyParam();
    //       return GetMyParam();
    //     });
    //     // Define the setter function for parameter 'example.test.myparam'.
    //     example.test.__defineSetter__('myparam', function(b) {
    //       // Call CefV8Handler::Execute() with the function name 'SetMyParam'
    //       // and a single argument.
    //       native function SetMyParam();
    //       if(b) SetMyParam(b);
    //     });
    //
    //     // Extension definitions can also contain normal JavaScript variables
    //     // and functions.
    //     var myint = 0;
    //     example.test.increment = function() {
    //       myint += 1;
    //       return myint;
    //     };
    //   })();
    // </pre> Example usage in the page: <pre>
    //   // Call the function.
    //   example.test.myfunction();
    //   // Set the parameter.
    //   example.test.myparam = value;
    //   // Get the parameter.
    //   value = example.test.myparam;
    //   // Call another function.
    //   example.test.increment();
    // </pre>
    tfn_cef_register_extension = function(
        const extension_name, javascript_code: PCefString;
        handler: PCefv8Handler): Integer; cdecl;
